<?php
/**
 * @author shenjun
 * @CreateDate 2010-10-19
 * @todo 修改框架核心JS位置
 */
class FController extends Controller {
	
	public function init()
	{
		Yii::app()->clientScript->coreScriptUrl = Yii::app()->baseUrl . "/js";
		//设置css路径
		YiiBase::setPathOfAlias( 'webcss' , YiiBase::getPathOfAlias('webroot') . '/css');
		$this->layout = 'application.views.layouts.adminRight';
		parent::init();
		$_GET['r'] = isset( $_GET['r'] ) ? $_GET['r'] : Yii::app()->homeUrl ; 
	}
	/**
	 * @todo 生成Url地址
	 * @desc 重写父类的，使其加上域名部份
	 * @see CController::createUrl()
	 */
	public function createUrl( $route , $params = array() , $ampersand = '&'){
		if($route==='')
			$route=$this->getId().'/'.$this->getAction()->getId();
		else if(strpos($route,'/')===false)
			$route=$this->getId().'/'.$route;
		if($route[0]!=='/' && ($module=$this->getModule())!==null)
			$route=$module->getId().'/'.$route;
		return Yii::app()->request->hostInfo . Yii::app()->createUrl(trim($route,'/'),$params,$ampersand);
	}
	/**
	 * @todo 结束程序，并输出json串
	 * @param string 状态
	 * @param array $array 需要输出的类容
	 */
	protected function EndforJson( $state , array $array = array() )
	{
		if ( $state === true )
			$state = 1;
		elseif ( $state === false )
			$state = 0;
		$exit = array(
			'succ' => $state
		);
		foreach ( $array  as $key => $val )
		{
			$exit[ $key ] = $val ;
		}
		echo json_encode( $exit );
		Yii::app()->end();
	} 
}